clear all
set more off
set trace off
set scheme s1mono


*---- SWITCHES ----*
local clean	= 1
local tables = 1
local nsctables = 1
local oemaside = 1
local subsamp_10perc = 0 

if `oemaside' == 1 {
	global outcomestorunprep postsecondary dis_tot ln_dis_tot any_dis any_worklim worklim_tot any_ssissdi ssissdi_tot
	global outcomestorun dis_tot ln_dis_tot any_dis  
	global outcomestorunT5 dis_tot any_dis  
}


*-----------------------------*
*---- Clean and prep data ----*
*-----------------------------*

if `clean'==1{
	if `oemaside' == 1{
		use "processed/cleaned_analysis_data_NSC_VADC_v7.dta", clear
	}
	
	
	if `oemaside' == 1{
		gen rnum=runiform()
		if `subsamp_10perc'==1{
			keep if rnum<.1
		}
		drop rnum

		forvalues k=0(1)19{
			foreach var in emodplus eminless e4np postsecondary e2 e4 assoconly assocplus bachplus {
			replace `var'_`k'=. if inrange(firstyear,1990,1998)
		}
		}
		
				g yr = year(firstafqtdt)
		g quarter = 1 if inrange(month(firstafqtdt),1,3)
		replace quarter = 2 if inrange(month(firstafqtdt),4,6)
		replace quarter = 3 if inrange(month(firstafqtdt),7,9)
		replace quarter = 4 if inrange(month(firstafqtdt),10,12)
		egen quarterFE = group(yr quarter)
	}
	
	foreach v in inst31 inst50 k31 k50 instk31 instk50 tri31 tri50 tri31_half tri50_half k31_2 k50_2 instk31_2 instk50_2 {
		cap drop `v'
	}
	foreach n in 31 50{
		gen inst`n'=(firstafqt>=`n')
		gen k`n'=firstafqt-`n'+.5
		gen instk`n'=inst`n'*k`n'	
		gen tri`n' = 1-abs((firstafqt - `n'+.5)/19)
		gen tri`n'_half = 1-abs((firstafqt - `n'+.5)/9)
		gen k`n'_2=k`n'^2
		gen instk`n'_2=instk`n'^2
	}
			
	if `oemaside'==0 rename quarter quarterFE

	
	if `oemaside' == 1 local benchmark dis_tot
	
	gen min_year_after_firstafqt=.
	forval k=0/19 {
		replace min_year_after_firstafqt=`k' if `benchmark'_`k'!=. & min_year_after_firstafqt==.
	}
	
	gen max_year_after_firstafqt=.
	forvalues k=19(-1)0 {
		replace max_year_after_firstafqt=`k' if `benchmark'_`k'!=. & max_year_after_firstafqt==.
	}
	
	gen yrs_observed_0_19=max_year_after_firstafqt-min_year_after_firstafqt+1

	gen yrs_observed_11_19=max(0,max_year_after_firstafqt-max(10,min_year_after_firstafqt))
	replace yrs_observed_11_19=0 if yrs_observed_11_19==.

	gen yrs_observed_15_19=max(0,max_year_after_firstafqt-max(14,min_year_after_firstafqt))
	replace yrs_observed_15_19=0 if yrs_observed_15_19==.
	
	egen max_yrs_observed=max(yrs_observed_0_19), by(firstyear)
	egen min_yrs_observed=min(yrs_observed_0_19), by(firstyear)
	assert max_yrs_observed==min_yrs_observed
	forvalues k=1990/2011 {
		disp `k'
		sum firstyear min_year_after_firstafqt max_year_after_firstafqt yrs_observed_* if firstyear==`k'
	}
	
if `oemaside' == 1 {
		forvalues k=0(1)19 {
gen ln_dis_tot_`k' = ln(dis_tot_`k')
}
}

	foreach n in $outcomestorunprep {
		egen `n'_0_19_mean=rowmean(`n'_0 `n'_1 `n'_2 `n'_3 `n'_4 `n'_5 `n'_6 `n'_7 `n'_8 `n'_9 `n'_10 `n'_11 `n'_12 `n'_13 `n'_14 `n'_15 `n'_16 `n'_17 `n'_18 `n'_19)
		egen `n'_11_19_mean=rowmean(`n'_11 `n'_12 `n'_13 `n'_14 `n'_15 `n'_16 `n'_17 `n'_18 `n'_19)
		egen `n'_15_19_mean=rowmean(`n'_15 `n'_16 `n'_17 `n'_18 `n'_19)
	}

	foreach n in 31 31_half 50 50_half {
		gen tri`n'_cum_0_19=tri`n'* yrs_observed_0_19
		gen tri`n'_cum_11_19=tri`n'*yrs_observed_11_19
		gen tri`n'_cum_15_19=tri`n'*yrs_observed_15_19
	}
	
	if `oemaside' == 1 {
	gen female = male==0 if !missing(male)
	encode(hor_state), gen(app_state)
	replace app_state=100 if missing(app_state)
	}
	
	compress
	gen all=1
	save "processed/cumulative-alt-7", replace
}	


*-----------------------------*
*---- TABLE A7 and A12 PANEL B ----*
*-----------------------------*

if `tables'==1{
if `oemaside' == 1 {
	
foreach samp in all black white { 
use "processed/cumulative-alt-7", clear

if "`samp'" == "black" keep if black == 1
if "`samp'" == "white" keep if white == 1

local n any_dis
egen maxanydis_0_19_mean =rowmax(`n'_0 `n'_1 `n'_2 `n'_3 `n'_4 `n'_5 `n'_6 `n'_7 `n'_8 `n'_9 `n'_10 `n'_11 `n'_12 `n'_13 `n'_14 `n'_15 `n'_16 `n'_17 `n'_18 `n'_19)

local n any_worklim
egen maxanywl_0_19_mean =rowmax(`n'_0 `n'_1 `n'_2 `n'_3 `n'_4 `n'_5 `n'_6 `n'_7 `n'_8 `n'_9 `n'_10 `n'_11 `n'_12 `n'_13 `n'_14 `n'_15 `n'_16 `n'_17 `n'_18 `n'_19)

local n any_ssissdi 
egen mxssissdi_0_19_mean =rowmax(`n'_0 `n'_1 `n'_2 `n'_3 `n'_4 `n'_5 `n'_6 `n'_7 `n'_8 `n'_9 `n'_10 `n'_11 `n'_12 `n'_13 `n'_14 `n'_15 `n'_16 `n'_17 `n'_18 `n'_19)

local outcomelist maxanydis any_dis maxanywl any_worklim dis_tot 

		eststo clear

		foreach outcome in `outcomelist' {
			foreach cut in 31 50 {
				preserve
				if `cut'==31{
					keep if inrange(firstafqt,12,49) 
					keep `outcome'_0_19_mean  k`cut' k`cut'_2 instk`cut' instk`cut'_2 quarterFE access inst`cut' yrs_observed_0_19 yrs_observed_11_19 yrs_observed_15_19 firstyear
				}
				if `cut'==50{
					keep if inrange(firstafqt,31,68)
				keep  `outcome'_0_19_mean  k`cut' k`cut'_2 instk`cut' instk`cut'_2 quarterFE access inst`cut' yrs_observed_0_19 yrs_observed_11_19 yrs_observed_15_19 firstyear
				}

				if ("`outcome'" == "maxanydis" | "`outcome'" == "maxanywl" | "`outcome'" == "mxssissdi" )  {
				eststo `outcome'_`cut': ivregress 2sls `outcome'_0_19_mean k`cut' k`cut'_2 instk`cut' instk`cut'_2 i.quarterFE (access=inst`cut') if inrange(firstyear,1990,2011) , robust
				qui summ `outcome'_0_19_mean if e(sample)
				estadd scalar depmean = r(mean)			
				}

				if ("`outcome'" != "maxanydis" & "`outcome'" != "maxanywl" & "`outcome'" != "mxssissdi" )  {
				eststo `outcome'_`cut': ivregress 2sls `outcome'_0_19_mean k`cut' k`cut'_2 instk`cut' instk`cut'_2 i.quarterFE (access=inst`cut') [aweight = yrs_observed_0_19] if inrange(firstyear,1990,2011) , robust
				qui summ `outcome'_0_19_mean [aweight = yrs_observed_0_19] if e(sample)
				estadd scalar depmean = r(mean)
				}
				
				restore
				} 
			} 

				noi esttab  maxanydis_31 any_dis_31 maxanywl_31 any_worklim_31 dis_tot_31 ///
				maxanydis_50 any_dis_50 maxanywl_50 any_worklim_50 dis_tot_50 ///
				using "output\TableA7orA12_panelB_`samp'.tex",	///
							cells(b(fmt(3) star) se(par fmt(3)))  ///
								replace noobs nomtitle nodepvar nonumber plain fragment label ///	
								substitute(_ \_) style(tex) ///	
								mlabels(, none) collabels(, none) prehead( 2SLS   \\ )	///			
								keep(access, relax) ///
								varlabels(access "Enlist (2SLS)") ///
								starlevels(* 0.1 ** 0.05 *** 0.01) varwidth(30) ///
								stats(N depmean, labels("\hline \\ Observations" "Dep. Var Mean") fmt(%16.0gc 3))


}
}
}


*-----------------------------*
*---- TABLE A15----*
*-----------------------------*

foreach grp in black white {
	use processed/cumulative-alt-7, clear 
	cap drop all
	g all = 1 
	keep if `grp' == 1 
		foreach outcome in  dis_tot  {

		local conttoggle 0 
		local controls
		local controlskeep
		
		local olstoggle = 0
		

		eststo clear
			foreach cut in 31 50 {
				preserve
				if `cut'==31{
					keep if inrange(firstafqt,12,49) 
					keep `controlskeep' `outcome'_0_19_mean `outcome'_11_19_mean `outcome'_15_19_mean firstafqt k`cut' k`cut'_2 instk`cut' instk`cut'_2 quarterFE access inst`cut' yrs_observed_0_19 yrs_observed_11_19 yrs_observed_15_19 firstyear
				}
				if `cut'==50{
					keep if inrange(firstafqt,31,68)
				keep  `controlskeep' `outcome'_0_19_mean `outcome'_11_19_mean `outcome'_15_19_mean firstafqt k`cut' k`cut'_2 instk`cut' instk`cut'_2 quarterFE access inst`cut' yrs_observed_0_19 yrs_observed_11_19 yrs_observed_15_19 firstyear
				}

				
				if `olstoggle' == 0 {
				eststo `outcome'_0_19_`cut': ivregress 2sls `outcome'_0_19_mean k`cut' k`cut'_2 instk`cut' instk`cut'_2 i.quarterFE `controls'   (access=inst`cut') [aweight = yrs_observed_0_19] if inrange(firstyear,1990,2011) , robust
				qui summ `outcome'_0_19_mean [aweight = yrs_observed_0_19] if e(sample)
				estadd scalar depmean = r(mean)
				
				eststo `outcome'_11_19_`cut': ivregress 2sls `outcome'_11_19_mean k`cut' k`cut'_2 instk`cut' instk`cut'_2 i.quarterFE `controls'  (access=inst`cut') [aweight = yrs_observed_11_19] if inrange(firstyear,1990,2007) , robust
				qui summ `outcome'_11_19_mean [aweight = yrs_observed_11_19] if e(sample)
				estadd scalar depmean = r(mean)

				}
				
				
				restore
				
				} 
				
				noi esttab  `outcome'_11_19_31  ///
						     `outcome'_11_19_50 using ///
							".\output\TableA15_dis_tot_11_19_`grp'.tex",	///
							cells(b(fmt(0) star) se(par fmt(0)))  ///
								replace noobs nomtitle nodepvar nonumber plain fragment label ///	
								substitute(_ \_) style(tex) ///	
								mlabels(, none) collabels(, none) prehead( 2SLS   \\ )	///			
								keep(access, relax) ///
								varlabels(access "Enlist (2SLS)") ///
								starlevels(* 0.1 ** 0.05 *** 0.01) varwidth(30) ///
								stats(N depmean, labels("\hline \\ Observations" "Dep. Var Mean") fmt(%16.0gc 0))
				
		} 
} 

*-----------------------------*
*---- TABLE A7 and A12 PANEL A ----*
*-----------------------------*

if `tables'==1{
if `oemaside' == 1 {

foreach samp in all black white { 

use "processed/cumulative-alt-7", clear

if "`samp'" == "black" keep if black == 1
if "`samp'" == "white" keep if white == 1


local n assocplus 
egen maxassocplus_0_19_mean =rowmax(`n'_0 `n'_1 `n'_2 `n'_3 `n'_4 `n'_5 `n'_6 `n'_7 `n'_8 `n'_9 `n'_10 `n'_11 `n'_12 `n'_13 `n'_14 `n'_15 `n'_16 `n'_17 `n'_18 `n'_19)
local n assoconly
egen maxassoconly_0_19_mean =rowmax(`n'_0 `n'_1 `n'_2 `n'_3 `n'_4 `n'_5 `n'_6 `n'_7 `n'_8 `n'_9 `n'_10 `n'_11 `n'_12 `n'_13 `n'_14 `n'_15 `n'_16 `n'_17 `n'_18 `n'_19)
local n bachplus
egen maxbachplus_0_19_mean =rowmax(`n'_0 `n'_1 `n'_2 `n'_3 `n'_4 `n'_5 `n'_6 `n'_7 `n'_8 `n'_9 `n'_10 `n'_11 `n'_12 `n'_13 `n'_14 `n'_15 `n'_16 `n'_17 `n'_18 `n'_19)

local outcomelist maxassocplus maxassoconly maxbachplus

		eststo clear

		foreach outcome in `outcomelist' {
			foreach cut in 31 50 {
				preserve
				if `cut'==31{
					keep if inrange(firstafqt,12,49) 
					keep `outcome'_0_19_mean  k`cut' k`cut'_2 instk`cut' instk`cut'_2 quarterFE access inst`cut' yrs_observed_0_19 yrs_observed_11_19 yrs_observed_15_19 firstyear
				}
				if `cut'==50{
					keep if inrange(firstafqt,31,68)
				keep  `outcome'_0_19_mean  k`cut' k`cut'_2 instk`cut' instk`cut'_2 quarterFE access inst`cut' yrs_observed_0_19 yrs_observed_11_19 yrs_observed_15_19 firstyear
				}

				eststo `outcome'_`cut': ivregress 2sls `outcome'_0_19_mean k`cut' k`cut'_2 instk`cut' instk`cut'_2 i.quarterFE (access=inst`cut') if inrange(firstyear,1999,2011) , robust
				qui summ `outcome'_0_19_mean if e(sample)
				estadd scalar depmean = r(mean)			
				restore
				} 
			} 

				noi esttab  maxassocplus_31 maxassoconly_31 maxbachplus_31 ///
				maxassocplus_50 maxassoconly_50 maxbachplus_50 ///
				using  "output\TableA7orA12_panelA_`samp'.tex",	///
							cells(b(fmt(3) star) se(par fmt(3)))  ///
								replace noobs nomtitle nodepvar nonumber plain fragment label ///	
								substitute(_ \_) style(tex) ///	
								mlabels(, none) collabels(, none) prehead( 2SLS   \\ )	///			
								keep(access, relax) ///
								varlabels(access "Enlist (2SLS)") ///
								starlevels(* 0.1 ** 0.05 *** 0.01) varwidth(30) ///
								stats(N depmean, labels("\hline \\ Observations" "Dep. Var Mean") fmt(%16.0gc 3))
}
}
}

*-----------------------------*
*---- TABLE A8 ----*
*-----------------------------*

if `nsctables'==1{
if `oemaside' == 1 {

use "processed/cumulative-alt-7", clear

foreach n in postsecondary e4 e4np e4privfp e2 emodplus eminless assocplus assoconly bachplus  {
egen `n'_m =rowmax(`n'_0 `n'_1 `n'_2 `n'_3 `n'_4 `n'_5 `n'_6 `n'_7 `n'_8 `n'_9 `n'_10 `n'_11 `n'_12 `n'_13 `n'_14 `n'_15 `n'_16 `n'_17 `n'_18 `n'_19)
}


		eststo clear

		local row = 0 
		foreach outcome in postsecondary e4 e4np e4privfp e2 emodplus eminless     { 
		local row = `row' + 1
		if "`outcome'" == "postsecondary" local l Attend Post-Secondary
		if "`outcome'" == "e4" local l Attend 4-Yr College
		if "`outcome'" == "e4np" local l Attend 4-Yr Non-Profit (Pub. or Priv)
		if "`outcome'" == "e4privfp" local l Attend 4-Yr For-Profit 
		if "`outcome'" == "e2" local l Attend 2-Yr College
		if "`outcome'" == "emodplus"  local l Attend At Least Mod. Selective
		if "`outcome'" == "eminless"  local l Attend Min. Selective Or Less
		if "`outcome'" == "assocplus" local l Graduated
		if "`outcome'" == "assoconly" local l Assoc. Degree 
		if "`outcome'" == "bachplus" local l Bach. Degree or Higher
		if "`outcome'" == "assocplusXstemn" local l Graduated STEM NSF

			foreach cut in 31 50 {
				preserve
				if `cut'==31{
					keep if inrange(firstafqt,12,49) 
					keep `outcome'_m  k`cut' k`cut'_2 instk`cut' instk`cut'_2 quarterFE access inst`cut' firstyear
				}
				if `cut'==50{
					keep if inrange(firstafqt,31,68)
				keep  `outcome'_m  k`cut' k`cut'_2 instk`cut' instk`cut'_2 quarterFE access inst`cut' firstyear
				}

				eststo `outcome'_m_`cut' : ivregress 2sls `outcome'_m  k`cut' k`cut'_2 instk`cut' instk`cut'_2 i.quarterFE (access=inst`cut') if inrange(firstyear,1999,2011) , robust
				qui summ `outcome'_m  if e(sample)
				estadd scalar depmean = r(mean)			
				restore
				} 
				
				if `row' != 7 {
				noi esttab  `outcome'_m_31 `outcome'_m_50   using "output\TableA8_row`row'.tex",	///
							cells(b(fmt(3) star) se(par fmt(3)))  ///
								replace noobs nomtitle nodepvar nonumber plain fragment label ///	
								substitute(_ \_) style(tex) ///	
								mlabels(, none) collabels(, none) 	///			
								keep(access, relax) ///
								varlabels(access "`l'") ///
								starlevels(* 0.1 ** 0.05 *** 0.01) varwidth(30) ///
								stats()
			}
							if `row' == 7 {
				noi esttab  `outcome'_m_31 `outcome'_m_50   using "output\TableA8_row`row'.tex",	///
							cells(b(fmt(3) star) se(par fmt(3)))  ///
								replace noobs nomtitle nodepvar nonumber plain fragment label ///	
								substitute(_ \_) style(tex) ///	
								mlabels(, none) collabels(, none) 	///			
								keep(access, relax) ///
								varlabels(access "`l'") ///
								starlevels(* 0.1 ** 0.05 *** 0.01) varwidth(30) ///
								stats(N, labels("\hline \\ Observations") fmt(0))
			}

}
}
}


*-----------------------------*
*---- TABLE A13 and A14 panel b ----*
*-----------------------------*



use "processed/cumulative-alt-7", clear


foreach n in postsecondary e4 e4np e4privfp e2 emodplus eminless  assocplus assoconly bachplus assocplusXstemn { // 
egen `n'_m =rowmax(`n'_0 `n'_1 `n'_2 `n'_3 `n'_4 `n'_5 `n'_6 `n'_7 `n'_8 `n'_9 `n'_10 `n'_11 `n'_12 `n'_13 `n'_14 `n'_15 `n'_16 `n'_17 `n'_18 `n'_19)
}

		eststo clear

		local row = 0 
		foreach outcome in  postsecondary e4 e4np e4privfp e2 emodplus eminless assocplusXstemn  {
		local row = `row' + 1

		if "`outcome'" == "postsecondary" local l Attend Post-Secondary
		if "`outcome'" == "e4" local l Attend 4-Yr College
		if "`outcome'" == "e4np" local l Attend 4-Yr Non-Profit (Pub. or Priv)
		if "`outcome'" == "e4privfp" local l Attend 4-Yr For-Profit 
		if "`outcome'" == "e2" local l Attend 2-Yr College
		if "`outcome'" == "emodplus"  local l Attend At Least Mod. Selective
		if "`outcome'" == "eminless"  local l Attend Min. Selective Or Less
		if "`outcome'" == "assocplus" local l Graduated
		if "`outcome'" == "assoconly" local l Assoc. Degree 
		if "`outcome'" == "bachplus" local l Bach. Degree or Higher
		if "`outcome'" == "assocplusXstemn" local l Graduated STEM NSF

		foreach samp in black white { 
			foreach cut in 31 50 {
				preserve
				if `cut'==31{
					keep if inrange(firstafqt,12,49) 
					keep `outcome'_m  k`cut' k`cut'_2 instk`cut' instk`cut'_2 quarterFE access inst`cut' firstyear `samp'
					keep if `samp' == 1 
				}
				if `cut'==50{
					keep if inrange(firstafqt,31,68)
				keep  `outcome'_m  k`cut' k`cut'_2 instk`cut' instk`cut'_2 quarterFE access inst`cut' firstyear `samp'
				keep if `samp' == 1 
				}

				eststo `outcome'_m_`cut'_`samp' : ivregress 2sls `outcome'_m  k`cut' k`cut'_2 instk`cut' instk`cut'_2 i.quarterFE (access=inst`cut') if inrange(firstyear,1999,2011) , robust
				qui summ `outcome'_m  if e(sample)
				estadd scalar depmean = r(mean)			
				restore
				} 
			} 
			
				if `row' != 7 {
				noi esttab  `outcome'_m_31_black `outcome'_m_50_black `outcome'_m_31_white `outcome'_m_50_white using "output\TableA13or14_row`row'.tex",	///
							cells(b(fmt(3) star) se(par fmt(3)))  ///
								replace noobs nomtitle nodepvar nonumber plain fragment label ///	
								substitute(_ \_) style(tex) ///	
								mlabels(, none) collabels(, none) 	///			
								keep(access, relax) ///
								varlabels(access "`l'") ///
								starlevels(* 0.1 ** 0.05 *** 0.01) varwidth(30) ///
								stats()
			}
							if `row' == 7 {
				noi esttab  `outcome'_m_31_black `outcome'_m_50_black `outcome'_m_31_white `outcome'_m_50_white    using "output\TableA13or14_row`row'.tex",	///
							cells(b(fmt(3) star) se(par fmt(3)))  ///
								replace noobs nomtitle nodepvar nonumber plain fragment label ///	
								substitute(_ \_) style(tex) ///	
								mlabels(, none) collabels(, none) 	///			
								keep(access, relax) ///
								varlabels(access "`l'") ///
								starlevels(* 0.1 ** 0.05 *** 0.01) varwidth(30) ///
								stats(N, labels("\hline \\ Observations") fmt(0))
			}
			

}

*-----------------------------*
****** TABLE  A 11 ******
*-----------------------------*

 use "./processed/cleaned_mepcom.dta", clear
keep pid race ethnic 
isid pid
tempfile merg 
save 	`merg', replace

use "./processed/cumulative-alt-7", clear
merge 1:1 pid using `merg', keep(1 3) nogen
g year = firstyear
merge m:1 hor_state year quarter using "./raw/laus_quarterly_unemployment", keep(3) nogen
merge m:1 hor_state year quarter using "./raw/laus_pop_labor_force_1990_2011", keep(3) nogen

egen stXyq = group(hor_state year quarter)
g time = yq(year,quarter) 
egen state = group(hor_state)

assert population != .
assert unemployment != .
assert hor_state != ""
assert year != .
assert quarter != .

g numapp = 1 
g numblack = black 
g numwhite = white 

global ABSORB hor_state time

foreach spec in 1 2 3 {

preserve

if `spec' == 2 keep if inrange(firstafqt,12,49)
if `spec' == 3 keep if inrange(firstafqt,31,68)


collapse (sum) numapp numblack numwhite (mean) white black unemployment population, by(hor_state quarter time year) 
summ numapp numblack numwhite
g lnapp = ln(1+numapp)
g lnblack = ln(1+numblack)
g lnwhite = ln(1+numwhite)
g appper = numapp*100000/population
g blackper = numblack*100000/population
g whiteper = numwhite*100000/population

sort hor_state time 

isid hor_state time 

by hor_state:  g DeltaUnemp = unemployment - unemployment[_n-1]
by hor_state:  g lag1unemp =  unemployment[_n-1]

g lnap = ln(numapp)
g lnapper = ln(numapp*100000/population)

drop if year == 1990 & quarter == 1 
	                                             
eststo clear 
foreach out in appper lnapper black white { 
eststo pa`out'raw: reg `out' unemployment, vce(cluster hor_state)  
	summ `out' if e(sample)
	estadd scalar depmean = r(mean)
	estadd local FE1 
	estadd local FE2  
eststo pa`out'st: areg `out' unemployment, abs(hor_state)  vce(cluster hor_state)  
	summ `out' if e(sample)
	estadd scalar depmean = r(mean)
	estadd local FE1 X
	estadd local FE2  
eststo pa`out't: reg `out' unemployment i.time,  vce(cluster hor_state)  
	summ `out' if e(sample)
	estadd scalar depmean = r(mean)
	estadd local FE1 
	estadd local FE2  X
eststo pa`out'stt: areg `out' unemployment i.time, abs(hor_state)  vce(cluster hor_state)  
	summ `out' if e(sample)
	estadd scalar depmean = r(mean)
	estadd local FE1  X
	estadd local FE2  X


eststo pb`out'raw: reg `out' lag1unemp, vce(cluster hor_state)  
	summ `out' if e(sample)
	estadd scalar depmean = r(mean)
	estadd local FE1 
	estadd local FE2  
eststo pb`out'st: areg `out' lag1unemp, abs(hor_state)  vce(cluster hor_state)  
	summ `out' if e(sample)
	estadd scalar depmean = r(mean)
	estadd local FE1 X
	estadd local FE2  
eststo pb`out't: reg `out' lag1unemp i.time,  vce(cluster hor_state)  
	summ `out' if e(sample)
	estadd scalar depmean = r(mean)
	estadd local FE1 
	estadd local FE2  X
eststo pb`out'stt: areg `out' lag1unemp i.time, abs(hor_state)  vce(cluster hor_state)  
	summ `out' if e(sample)
	estadd scalar depmean = r(mean)
	estadd local FE1  X
	estadd local FE2  X
	
eststo pc`out'raw: reg `out' DeltaUnemp, vce(cluster hor_state)  
	summ `out' if e(sample)
	estadd scalar depmean = r(mean)
	estadd local FE1 
	estadd local FE2  
eststo pc`out'st: areg `out' DeltaUnemp, abs(hor_state)  vce(cluster hor_state)  
	summ `out' if e(sample)
	estadd scalar depmean = r(mean)
	estadd local FE1 X
	estadd local FE2  
eststo pc`out't: reg `out' DeltaUnemp i.time,  vce(cluster hor_state)  
	summ `out' if e(sample)
	estadd scalar depmean = r(mean)
	estadd local FE1 
	estadd local FE2  X
eststo pc`out'stt: areg `out' DeltaUnemp i.time, abs(hor_state)  vce(cluster hor_state)  
	summ `out' if e(sample)
	estadd scalar depmean = r(mean)
	estadd local FE1  X
	estadd local FE2  X 
}

noi esttab    pblnapperstt    pbblackstt   pbwhitestt   using "output\A11panel`spec'.tex", ///
							cells(b(fmt(3) star) se(par fmt(3)))  ///
								replace noobs nomtitle nodepvar nonumber plain fragment label ///	
								substitute(_ \_ % \%) style(tex) ///	
								mlabels(, none) collabels(, none) 	///			
								keep( lag1unemp , relax) ///
								varlabels(lag1unemp "Unemp. Rate (Last Quarter)") ///		
								starlevels(* 0.1 ** 0.05 *** 0.01) varwidth(30) ///
								stats(N depmean FE1 FE2, labels("\hline \\ Observations" "Dep. Var Mean" "State FE" "Year by Quarter FE") fmt(0 3 0 0))

restore		
}


*DIS SUMM STATS FOR TABLE A.2
cap mkdir ./output/main-estimates 
use "./processed/cleaned_analysis_data_NSC_VADC_v7.dta", clear
keep if inrange(firstyear,1990,2011)
g all = 1

tempfile a 
save `a', replace 

	foreach sample in all black white {
			use `a', clear 
		keep if `sample'==1
		forval y=-1/19{
			local yt = `y'
			if `y' == -1 local yt m1
			foreach outcome in any_dis dis_tot {
				*all applicants
				sum `outcome'_`yt'
				global m_`outcome'_`yt'_all = r(mean)
				global N_`outcome'_`yt'_all = r(N)
				*all analysis sample
				sum `outcome'_`yt' if inrange(firstafqt,12,68)
				global m_`outcome'_`yt' = r(mean)
				global N_`outcome'_`yt' = r(N)
				*analysis sample, access==1
				sum `outcome'_`yt' if inrange(firstafqt,12,68) & access==1
				global m_`outcome'_`yt'_access = r(mean)
				global N_`outcome'_`yt'_access = r(N)
				*analysis sample, access==0
				sum `outcome'_`yt' if inrange(firstafqt,12,68) & access==0
				global m_`outcome'_`yt'_noaccess = r(mean)
				global N_`outcome'_`yt'_noaccess = r(N)
			}	//end outcome loop
		} // end y loop
		
		clear
		set obs 1
		forval y=-1/19{
			di "`y'"
			local yt = `y'
			if `y' == -1 local yt m1
		foreach outcome in any_dis dis_tot {
			di "`outcome'"
			gen m_`outcome'_`yt'_all = ${m_`outcome'_`yt'_all}
			gen N_`outcome'_`yt'_all = ${N_`outcome'_`yt'_all}
			gen m_`outcome'_`yt' = ${m_`outcome'_`yt'}
			gen N_`outcome'_`yt' = ${N_`outcome'_`yt'}
			gen m_`outcome'_`yt'_access = ${m_`outcome'_`yt'_access}
			gen N_`outcome'_`yt'_access = ${N_`outcome'_`yt'_access}
			gen m_`outcome'_`yt'_noaccess = ${m_`outcome'_`yt'_noaccess}
			gen N_`outcome'_`yt'_noaccess = ${N_`outcome'_`yt'_noaccess}
		}	//end outcome loop
		}	//end y loop
		
		save "./output/main-estimates/dis-sumstats-`sample'", replace
	} // end sample loop 
	


